//货柜管理-货柜列表
App.util.ns('Admin.Cabinet.Cabinet');
App.pages.add((function(){
    var NS = Admin.Cabinet.Cabinet;
    var page = new App.Page({
        name: 'cabinet/cabinet/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-window-restore"></i>',
            content: '货柜管理'
        }, {
            content: '柜子管理'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/cabinet/cabinet',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'is_deposit', title: '是否交押金', width: '95px', items: [
                    [0, '否'],
                    [1, '是']
                ]},
                {type: 'select', name: 'status', title: '状态', width: '80px', items: [
                    [0, '未部署'],
                    [1, '已部署']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.cabinet.cabinet.create'},
                {parent: 'view', permission: 'op:admin.cabinet.cabinet.detail'},
                {parent: 'edit', permission: 'op:admin.cabinet.cabinet.update'},
                {type: 'inline', permission: 'gp:admin/cabinet/cell', name: '格子管理',
                    operation: function(dataTable, cabinet){
                        App.nav.open('cabinet/cell/index', {
                            cabinet_id: cabinet.id,
                            cabinet_name: cabinet.name
                        });
                    }
                },
                {type: 'inline', permission: 'op:admin.cabinet.cabinet.open',
                    name: '激活', operation: {type: 'change', url: 'open'},
                    conditions: [['status', '0']]
                },
                {type: 'inline', permission: 'op:admin.cabinet.cabinet.close',
                    name: '禁用', operation: {type: 'change', url: 'close'},
                    conditions: [['status', '1']]
                },
                {type: 'inline', permission: 'op:admin.cabinet.cabinet.need',
                    name: '交押金', operation: {type: 'change', url: 'need'},
                    conditions: [['is_deposit', '0']]
                },
                {type: 'inline', permission: 'op:admin.cabinet.cabinet.notneed',
                    name: '不交押金', operation: {type: 'change', url: 'notneed'},
                    conditions: [['is_deposit', '1']]
                },
                {type: 'multi', name: '状态', openable: true, items: [
                    {type: 'multi', permission: 'op:admin.cabinet.cabinet.multiOpen', name: '激活', operation: {type: 'change', url: 'multiOpen', confirm: true}},
                    {type: 'multi', permission: 'op:admin.cabinet.cabinet.multiClose', name: '禁用', operation: {type: 'change', url: 'multiClose', confirm: true}}
                ], permission:[
                    'op:admin.cabinet.cabinet.multiOpen',
                    'op:admin.cabinet.cabinet.multiClose'
                ]},
                {parent: 'drop', permission: 'op:admin.cabinet.cabinet.delete'},
                {parent: 'multiDrop', permission: 'op:admin.cabinet.cabinet.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.cabinet.cabinet.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());